package com.itheima.web.controller;

import com.itheima.domain.db.TestSoul;
import com.itheima.domain.db.TestSoulQuestion;
import com.itheima.domain.db.TestSoulQuestionsOption;
import com.itheima.util.ResultInfo;
import com.itheima.web.manager.TestSoulManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class TestSoulController {

    @Autowired
    private TestSoulManager testSoulManager;

    //获取题目列表
    @GetMapping("/testSoul/findAll")
    public ResultInfo findTestSoulList(
            String name,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ){
        //1.调用manager
        return testSoulManager.findTestSoulList(pageNum,pageSize,name);
    }

    //获取问题列表
    @GetMapping("/testSoul/findQuestion")
    public ResultInfo findQuestionList(
            String name,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            String timuId
    ){
        //1.调用manager
        return testSoulManager.findQuestionList(pageNum,pageSize,name,timuId);
    }

    //获取答案列表
    @GetMapping("/testSoul/findAnswer")
    public ResultInfo findAnswerList(
            String name,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            String wentiId
    ){
        //1.调用manager
        return testSoulManager.findAnswerList(pageNum,pageSize,name,wentiId);
    }

    //新增答案
    @PostMapping("/addanswer")
    public ResultInfo addAnswer(@RequestBody TestSoulQuestionsOption option){
        //2.调用manager
        testSoulManager.addAnswer(option);
        return ResultInfo.success(null);
    }

    //修改答案
    @PutMapping("/editanswer")
    public ResultInfo editAnswer(@RequestBody TestSoulQuestionsOption option){
        //2.调用manager
        testSoulManager.editAnswer(option);
        return ResultInfo.success(null);
    }

    //删除答案
    @DeleteMapping("/deleteanswer")
    public ResultInfo deleteAnswer(String id){
        //调用manager
        Long answerId = Long.valueOf(id);
        testSoulManager.deleteAnswer(answerId);
        return ResultInfo.success(null);
    }

    //根据id删除问题
    @DeleteMapping("/delete/question")
    public ResultInfo deleteQuestion(String id){
        //调用manager
        Long questionId = Long.valueOf(id);
        return testSoulManager.deleteQuestion(questionId);
    }

    //新增问题
    @PostMapping("/add/question")
    public ResultInfo addQuestion(@RequestBody TestSoulQuestion question){
        //调用manager
        testSoulManager.addQuestion(question);
        return ResultInfo.success(null);
    }

    //新增题目
    @PostMapping("/add/test")
    public ResultInfo addTest(@RequestBody TestSoul testSoul){
        //调用manager
        testSoulManager.addTest(testSoul);
        return ResultInfo.success(null);
    }

    //删除题目
    @DeleteMapping("/delete/test")
    public ResultInfo deleteTest(String id){
        //调用manager
        Long testId = Long.valueOf(id);
        testSoulManager.deleteTest(testId);
        return ResultInfo.success(null);
    }
}
